package com.hl.sfzy.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hl.sfzy.entity.Consultants;
import com.hl.sfzy.service.ConsultantsService;
import com.hl.sfzy.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/consultants")
@CrossOrigin
public class  ConsultantsController {
    @Autowired
    private ConsultantsService consultantsService;

    @RequestMapping("/selectAll")
    public R selectAll(@RequestParam(required = false ,defaultValue = "1")int pageNum,
                       @RequestParam(required = false,defaultValue = "5") int pageSize){
        PageHelper.startPage(pageNum,pageSize);
        PageInfo<Consultants> info = new PageInfo<>(consultantsService.selectAll());
        return R.ok(info);
    }
    @RequestMapping("/selectById")
    public R selectById(Long id){
        return R.ok(consultantsService.selectById(id));
    }
    @RequestMapping("/insert")
    public R insert(@RequestBody Consultants record){
        return R.ok(consultantsService.insert(record));
    }
    @RequestMapping("/updateById")
    public R updateById(@RequestBody Consultants record){
        return R.ok(consultantsService.updateById(record));
    }
    @RequestMapping("/deleteById")
    public R deleteById(Long id){
        return R.ok(consultantsService.deleteById(id));
    }
    @RequestMapping("/selectBySelective")
    public R selectBySelective(
            @RequestParam(required = false ,defaultValue = "1")int pageNum,
            @RequestParam(required = false,defaultValue = "5") int pageSize, Consultants record){
        PageHelper.startPage(pageNum,pageSize);
        PageInfo<Consultants> info = new PageInfo<>(consultantsService.selectBySelective(record));
        return R.ok(info);
    }
    @RequestMapping("/updateByIdSelective")
    public R updateByIdSelective(@RequestBody Consultants record){
        return R.ok(consultantsService.updateByIdSelective(record));
    }
    @RequestMapping("/insertSelective")
    public R insertSelective(@RequestBody Consultants record){
        return R.ok(consultantsService.insertSelective(record));
    }
    @GetMapping("/findByLevel")
    public R findByLevel(String level){
        return R.ok(consultantsService.findByLevel(level));
    }
}
